const _ = require('lodash')

const {Spider} = require('../index')


module.exports = class TestSpider extends Spider {
    startUrls() {
        return [
            'https://codingpy.com/book/head-first-design-patterns/',
            'https://codingpy.com/book/head-first-design-patterns/',
            'http://172.18.228.144:6002/12312312123',
            'http://httpbin.org/status/500',
            'http://httpbin.org/status/404',
        ]
    }

    parse(response, {follow}) {
        const {$} = response
        $('.post_list .main>a').each((_, el) => {
            follow($(el).attr('href'), {
                callback: this.parse_item,
            })
        })
    }

    parse_item(response, {collect}) {
        const {$} = response
        collect(_.trim($('title').text()))
    }
}
